unit UAddItem;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, AdvPanel,
  DBAdvGlowNavigator, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, UDMItems, cxContainer, cxGroupBox, cxTextEdit, cxDBEdit, Vcl.StdCtrls,
  cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox;

type
  TFAddItem = class(TForm)
    AdvPanel1: TAdvPanel;
    DBAdvGlowNavigator1: TDBAdvGlowNavigator;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1item_code: TcxGridDBColumn;
    cxGrid1DBTableView1internal_code: TcxGridDBColumn;
    cxGrid1DBTableView1cat_id: TcxGridDBColumn;
    cxGrid1DBTableView1cnss_coverage: TcxGridDBColumn;
    cxGrid1DBTableView1coop_coverage_1: TcxGridDBColumn;
    cxGrid1DBTableView1coop_coverage_2: TcxGridDBColumn;
    AdvPanelStyler1: TAdvPanelStyler;
    cxGroupBox1: TcxGroupBox;
    AdvPanel2: TAdvPanel;
    Label1: TLabel;
    cxDBTextEdit1: TcxDBTextEdit;
    Label2: TLabel;
    cxDBTextEdit2: TcxDBTextEdit;
    Label3: TLabel;
    cxDBLookupComboBox1: TcxDBLookupComboBox;
    Label4: TLabel;
    cxDBLookupComboBox2: TcxDBLookupComboBox;
    Label5: TLabel;
    cxDBLookupComboBox3: TcxDBLookupComboBox;
    Label6: TLabel;
    cxDBLookupComboBox4: TcxDBLookupComboBox;
    procedure DBAdvGlowNavigator1BtnCancel(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnEdit(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnFirst(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnInsert(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnLast(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnNext(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnPost(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnPrior(Sender: TObject);
    procedure DBAdvGlowNavigator1BtnRefresh(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FAddItem: TFAddItem;

implementation

{$R *.dfm}

procedure TFAddItem.DBAdvGlowNavigator1BtnCancel(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.Cancel;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnEdit(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := true;
  DMItems.his_items.Edit;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnFirst(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.First;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnInsert(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := true;
  DMItems.his_items.Insert;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnLast(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.Last;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnNext(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.Next;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnPost(Sender: TObject);
var hiddenID : string;
begin
  hiddenID := LowerCase('_'+StringReplace(cxDBLookupComboBox1.EditText, ' ', '',[rfReplaceAll, rfIgnoreCase])+'_'+StringReplace(cxDBTextEdit1.EditValue, ' ', '',[rfReplaceAll, rfIgnoreCase]));
  Self.AdvPanel1.Enabled := true;
  DMItems.his_items.FieldByName('hidden_id').Value := hiddenID;
  DMItems.his_items.Post;
  DMItems.his_items.RefreshRecord;
  Self.AdvPanel1.Enabled := false;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnPrior(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.Prior;
end;

procedure TFAddItem.DBAdvGlowNavigator1BtnRefresh(Sender: TObject);
begin
  Self.AdvPanel1.Enabled := false;
  DMItems.his_items.RefreshRecord;
end;

procedure TFAddItem.FormActivate(Sender: TObject);
begin
  DMItems.his_category.Refresh;
  DMItems.his_coverage.Refresh;
end;

end.
